package com.empsys.old.aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author wzm
 * @create 2023-12-16 11:34
 * project_name:web2310
 * @Description
 */
//@Aspect
//@Component
@Slf4j
//@Order(1)
public class AspectTest2 {

    //抽取切入点表达式
    @Pointcut("execution(* com.empsys.service.impl.*.*(..))")
    public void pt(){//切入点方法 如果需要提供给别的类使用public修饰

    }


    //前置通知 引入切入点方法
    @Before("pt()")
    public void before(JoinPoint joinPoint){
        log.info("前置通知2...");
    }


    //环绕通知 ProceedingJoinPoint只有环绕通知需要用这个调用
    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("环绕前2...");
        Object proceed = proceedingJoinPoint.proceed();//调用方法
        log.info("环绕后2...");
        return proceed;
    }


    //后置通知  无论有没有异常
    @After("pt()")
    public void after(JoinPoint joinPoint){
        log.info("后置通知2...");

    }


    //返回后通知 程序正常执行后后执行 有异常不会执行
    @AfterReturning("pt()")
    public void afterReturn(JoinPoint joinPoint){
        log.info("返回后通知2...");

    }

    //异常通知
    @AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint){
        log.info("异常通知2...");
    }




}
